#!/bin/bash

# 远程服务器信息
REMOTE_HOST="121.89.84.104"
REMOTE_USER="root"
REMOTE_DIR="/var/www/html4"
LOCAL_DIST_DIR="./remote_web"

cp ./build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ./remote_web/app-arm64-v8a-release.apk

# 2. 删除远程服务器目录内容
echo "正在清理远程服务器目录..."
ssh ${REMOTE_USER}@${REMOTE_HOST} "rm -rf ${REMOTE_DIR}/*"
if [ $? -ne 0 ]; then
    echo "远程清理失败，但是无所谓！"
fi
echo "远程目录清理完成！"

# 3. 上传构建文件
echo "正在上传文件到远程服务器..."
scp -r ${LOCAL_DIST_DIR}/* ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/
if [ $? -ne 0 ]; then
    echo "文件上传失败！"
    exit 1
fi
echo "文件上传成功！"

echo "部署完成！"